package com.xh.car.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xh.car.bean.Apply;
import com.xh.car.mapper.ApplyMapper;
import com.xh.car.service.ApplyService;
import com.xh.car.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author PangJunjie
 * @Date 2024/5/14/014
 */
@Service
@Transactional
public class ApplyServiceImpl implements ApplyService {
    @Autowired
    private ApplyMapper applyMapper;

    @Override
    public void saveOrUpdate(Apply apply) {
        if (apply.getId() == null) {
            applyMapper.insertSelective(apply);
        } else {
            applyMapper.updateByPrimaryKeySelective(apply);
        }
    }

    @Override
    public R getPage(int page, int limit, Apply apply) {
        PageHelper.startPage(page, limit);
        List<Apply> list = applyMapper.getAll(apply);
        PageInfo<Apply> pageInfo = new PageInfo<>(list);
        return R.page(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public Apply getById(int id) {
        return applyMapper.selectByPrimaryKey(id);
    }

    @Override
    public void delete(int id) {
        applyMapper.deleteByPrimaryKey(id);
    }
}
